# -*-* encoding:UTF-8 -*-
# author : mengy
# date   : 2018/11/22

from xml.dom.minidom import parse
import xml.dom.minidom

# 使用minidom解析器打开 XML 文档
DOMTree = xml.dom.minidom.parse("movies.xml")
collection = DOMTree.documentElement
if collection.hasAttribute("shelf"):
    print "Root Element : %s" % collection.getAttribute("shelf")

# 在集合中获取所有电影
movies = collection.getElementsByTagName("movie")

# 打印每部电影的详细信息
for m in movies:
    print "------------Movies-------------"
    if m.hasAttribute("title"):
        print "Title : %s " % m.getAttribute("title")

    type = m.getElementsByTagName('type')[0]
    print "Type : %s" % type.childNodes[0].data
    format = m.getElementsByTagName('format')[0]
    print "Format : %s" % type.childNodes[0].data
    rating = m.getElementsByTagName('rating')[0]
    print "Rating : %s" % type.childNodes[0].data
    description = m.getElementsByTagName('description')[0]
    print "Description : %s" % type.childNodes[0].data
